package com.yn.xgame.logic.player;

import java.util.List;
import java.util.stream.Collectors;

import com.yn.xgame.logic.GamePlayer;
import com.yn.xgame.message.C2GPbRedirectMessage;
import com.yn.xgame.pb.GateClientProto;
import com.yn.xgame.pb.MessageIdProto;

public class BackPackModule {
	@Override
	public String toString() {
		return "BackPackModule [player=" + player + ", list=" + list + "]";
	}

	GamePlayer player;
	
	private List<BackPack> list;

	public List<BackPack> getList() {
		return list;
	}

	public void setList(List<BackPack> list) {
		this.list = list;
	}

	public BackPackModule(GamePlayer player, List<BackPack> list) {
		super();
		this.player = player;
		this.list = list;
	}

	public void handleQueryBackPack(C2GPbRedirectMessage msg) {
		
		GateClientProto.G2CMessage resp= GateClientProto.G2CMessage.newBuilder()
				.setMsgid(MessageIdProto.MessageId.G2C_UserBackPackResp)
				.setUserBackPack(
						GateClientProto.UserBackPack.newBuilder()
						.addAllBackpack(
								list.stream().map(BackPack::build).collect(Collectors.toList())
						)
				).build();
				
		player.respToClient(msg.getFromGateTopic(),resp);
	}
	

}
